﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SSABSZ.SuperEP.Core
{
    public static class Util
    {
        public static bool SettingStringTrue(string sto)
        {
            var str = sto.Trim();
            return (str.Length != 0 && (str.ElementAt(0) == 'Y' || str.ElementAt(0) == 'T' || str.ElementAt(0) == '1'));
        }

        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out Guid guid);
        public static Guid NewSequentialId()
        {
            Guid guid;
            UuidCreateSequential(out guid);
            var s = guid.ToByteArray();
            var t = new byte[16];
            for (var lop = 0; lop < 4; lop++) t[3-lop]    = s[lop];
            for (var lop = 0; lop < 2; lop++) t[5-lop]    = s[4+lop];
            for (var lop = 0; lop < 2; lop++) t[7 - lop]  = s[6 + lop];
            for (var lop = 0; lop < 2; lop++) t[8 + lop]  = s[8 + lop];
            for (var lop = 0; lop < 6; lop++) t[10 + lop] = s[10 + lop];
            return new Guid(t);
        }
    }
}
